{% include "GdsVenteBundle::Facture/facture_edit.html.twig" %}
<script>
    $(document).ready(function() {
        $('#departement').val({{user.departement.id}})
        $('#departement').attr('disabled', true);
        $('#submit_form_facture').val('Duppliquer')
        mdp = ""
        var fullDate = new Date();
        var twoDigitMonth = fullDate.getMonth()
        twoDigitMonth++
        twoDigitMonth += "";
        if (twoDigitMonth.length == 1)
            twoDigitMonth = "0" + twoDigitMonth;
        var twoDigitDate = fullDate.getDate() + "";
        if (twoDigitDate.length == 1)
            twoDigitDate = "0" + twoDigitDate;
        var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
        $("#gds_ventebundle_bonlivraisontype_date").val(currentDate)
        timerId = setInterval(time, 1000);
        $('#retour2').click(function() {
            clearInterval(timerId);
        })
        $('#submit_form_facture').click(function() {
            if ($('#form_facture').valid()) {
                $.ajax({
                    url: '{{path("gds_vente_facture_duppliquer")}}',
                    type: "POST",
                    datatype: 'json',
                    data: $('#form_facture').serialize() + '&articles={"articles":' + JSON.stringify(articles) + '}&heure=' + $('#heure').val() + '&id=' + '{{id}}' + '&departement=' + $('#departement option:selected').text() + '&mdp=' + mdp,
                    success: function(data) {
                        if (data.success) {
                            $.msgBox({
                                title: "Facture",
                                content: "Enregistrement Effectué avec succés",
                                type: "info",
                                buttons: [{value: "OK"}],
                                success: function(result) {
                                    location.reload();
                                }
                            });
                        } else if (data.limit_depass) {
                            $.msgBox({
                                title: "Dépassement du Solde Client !!",
                                content: "mdp: <input id='mdp' type='password' />",
                                type: "confirm",
                                buttons: [
                                    {type: "submit", value: "Valider"},
                                    {type: "cancel", value: "Annuler"}
                                ],
                                afterShow: function() {
                                    $('#mdp').focus()
                                },
                                success: function(result) {
                                    if (result == "Valider") {
                                        if ($('#mdp').val() != '') {
                                            mdp = $('#mdp').val()
                                            $('#submit_form_facture').click()
                                        }
                                    }
                                }
                            });
                        } else {
                            $.msgBox({
                                title: "Facture",
                                content: "Erreur D'enregistrement",
                                type: "error",
                                buttons: [{value: "OK"}]
                            });
                        }
                    },
                    error: function(e) {
                        $.msgBox({
                            title: "Facture",
                            content: "Erreur D'enregistrement",
                            type: "error",
                            buttons: [{value: "OK"}],
                            success: function(result) {

                            }
                        });
                    }
                })
            }
        })
        $('#start').hide()
    })
</script>